/* Copyright 2018-2020,2022,2023 NXP.
 *
 * NXP Confidential. This software is owned or controlled by NXP and may only be
 * used strictly in accordance with the applicable license terms. By expressly
 * accepting such terms or by downloading,installing, activating and/or otherwise
 * using the software, you are agreeing that you have read,and that you agree to
 * comply with and are bound by, such license terms. If you do not agree to be
 * bound by the applicable license terms, then you may not retain, install, activate
 * or otherwise use the software.
 *
 */

#ifndef UWBAPI_PROPRIETARY_SR040_H
#define UWBAPI_PROPRIETARY_SR040_H

#ifdef __cplusplus
extern "C" {
#endif

#include "phUwbTypes.h"
#include <UwbApi_Types_Proprietary.h>
#include <UwbApi_Types.h>

#define RX_RADIO_SETTING_SIZE     (512)
#define TX_RADIO_SETTING_SIZE     (256)
#define RX_RADIO_CONFIG_END_INDEX (16)
#define TX_RADIO_CONFIG_END_INDEX (32)
#define TOTAL_RADIO_CONFIG_WIDTH  (16)

#define MAX_RADIO_CONFIG_SIZE (RX_RADIO_SETTING_SIZE + TX_RADIO_SETTING_SIZE) * TOTAL_RADIO_CONFIG_WIDTH

/**
 * @brief  Structure lists out the Radio configs settings.
 */
typedef struct phRadioConfigInfo
{
    /** Pointer to the Radio configuration table settings */
    const uint8_t *radio_settings_table;
    /** size of Radio configuration table settings */
    uint32_t radio_settings_table_size;
    /** Pointer to the Radio configuration table CRC settings */
    const uint16_t *radio_settings_crc;
    /** Size of  Radio configuration table CRC settings */
    uint32_t radio_settings_crc_size;
    /** Force update or Safe Update */
    bool force_update;
} phRadioConfigInfo_t;

/** \addtogroup uwb_apis_sr040
 *
 * @{ */

/**
 * @brief APIs exposed to application to access UWB Functionality of SR040.
 */

/**
 * @brief API to put the device in HPD mode
 * \retval #UWBAPI_STATUS_OK               on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED  if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_FAILED           otherwise
 * \retval #UWBAPI_STATUS_TIMEOUT          if command is timeout
 */
EXTERNC tUWBAPI_STATUS UwbApi_SuspendDevice(void);

/**
 * @brief Set Default Core configs
 *
 *
 * \retval #UWBAPI_STATUS_OK                 on success
 * \retval #UWBAPI_STATUS_FAILED             otherwise
 */
EXTERNC tUWBAPI_STATUS UwbApi_SetDefaultCoreConfigs();

/**
 * @brief      Set core config DPD Timeout for SR040
 *
 * \param[in]  dpd_timeout  The dpd timeout
 *
 * Max value 5000.  Min value, determined by the host
 *
 * @return     Status of setting the value.
 */
EXTERNC tUWBAPI_STATUS UwbApi_PropSR040_SetDPDTimeout(uint16_t dpd_timeout);

/**
 * @brief      Set core config HPD Timeout for SR040
 *
 * \param[in]  hpd_timeout  The hpd timeout
 *
 * Max value 5000.  Min value, determined by the host
 *
 * @return     Status of setting the value.
 */
EXTERNC tUWBAPI_STATUS UwbApi_PropSR040_SetHPDTimeout(uint16_t hpd_timeout);

/**
 * @brief API to mange the session related info in NVM
 *
 * \param[in] sesNvmManageTag   Session NVM manage tag field
 * \param[in] sessionid         Session NVM manage session id field.
 * [Not present for the tag SESSION_NVM_MANAGE_DELETE_ALL. But pass sessionid = 0 [Any value] which is ignored ]
 *
 * \retval #UWBAPI_STATUS_OK               on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED  if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_INVALID_PARAM    if tag option is incorrect
 * \retval #UWBAPI_STATUS_TIMEOUT          if command is timeout
 * \retval #UWBAPI_STATUS_FAILED           otherwise
 */
EXTERNC tUWBAPI_STATUS UwbApi_SessionNvmManage(esessionNvmManage sesNvmManageTag, uint32_t sessionid);

/**
 * @brief API to start the device in Continuous Wave Mode
 *
 * \param[in] testMode   Test Mode to be started
 * \param[in] testModeParams   param used for the corresponding test mode
 *
 * \retval #UWBAPI_STATUS_OK               on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED  if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_INVALID_PARAM    if any of the input parameter is NULL or invalid value
 * \retval #UWBAPI_STATUS_FAILED           otherwise
 * \retval #UWBAPI_STATUS_TIMEOUT          if command is timeout
 */
EXTERNC tUWBAPI_STATUS UwbApi_StartTestMode(eTestMode testMode, const phTestModeParams *testModeParams);

/**
 * @brief API to stop Test Mode
 *
 * \retval #UWBAPI_STATUS_OK               on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED  if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_FAILED           otherwise
 * \retval #UWBAPI_STATUS_TIMEOUT          if command is timeout
 */
EXTERNC tUWBAPI_STATUS UwbApi_StopTestMode();

/**
 * @brief Set calibration parameters.
 *
 * \param[in] paramId       Calibration parameter ID
 * \param[in] pCalibData     Calibration Data
 * \param[out] calibResp      Calibration Status
 *
 * \retval #UWBAPI_STATUS_OK                 on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED    if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_INVALID_PARAM      if invalid parameters are passed
 * \retval #UWBAPI_STATUS_FAILED             otherwise
 * \retval #UWBAPI_STATUS_TIMEOUT            if command is timeout
 */
EXTERNC tUWBAPI_STATUS UwbApi_SetCalibration(
    eCalibParam paramId, phCalibrationData *pCalibData, phCalibrationStatus_t *calibResp);

/**
 * @brief Get calibration parameters.
 *
 * \param[in] paramId    Calibration param Id
 * \param[out] calibResp   Pointer to \ref phCalibRespStatus_t
 *
 * \retval #UWBAPI_STATUS_OK                 on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED    if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_INVALID_PARAM      if invalid parameters are passed
 * \retval #UWBAPI_STATUS_SESSION_NOT_EXIST  if session is not initialized with
 *                                            sessionId
 * \retval #UWBAPI_STATUS_TIMEOUT            if command is timeout
 * \retval #UWBAPI_STATUS_FAILED             otherwise
 */
EXTERNC tUWBAPI_STATUS UwbApi_GetCalibration(eCalibParam paramId, phCalibRespStatus_t *calibResp);

/**
 * @brief Radio Config Get CRC api.
 *
 * \param[in] radioConfigIndex   Radio Configuration index value. 0x00  0x0F for Rx and 0x10  0x1F for Tx
 * \param[out] pCrc   Radio Config CRC
 *
 * \retval #UWBAPI_STATUS_OK                 on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED    if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_INVALID_PARAM      if invalid parameters are passed
 * \retval #UWBAPI_STATUS_TIMEOUT            if command is timeout
 * \retval #UWBAPI_STATUS_BUFFER_OVERFLOW    if response buffer is not sufficient to hold the response
 * \retval #UWBAPI_STATUS_FAILED             otherwise
 */
EXTERNC tUWBAPI_STATUS UwbApi_RadioConfigGetCrc(uint8_t radioConfigIndex, uint16_t *pCrc);

/**
 * @brief Radio Config Get CRC api.
 *
 * \param[out] pCrc   CRC for over all radio settings
 *
 * \retval #UWBAPI_STATUS_OK                 on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED    if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_INVALID_PARAM      if invalid parameters are passed
 * \retval #UWBAPI_STATUS_TIMEOUT            if command is timeout
 * \retval #UWBAPI_STATUS_BUFFER_OVERFLOW    if response buffer is not sufficient to hold the response
 * \retval #UWBAPI_STATUS_FAILED             if inital empty radio settings were not yet present
 */
EXTERNC tUWBAPI_STATUS UwbApi_RadioConfigGetAllCrc(uint16_t *pCrc);

/**
 * @brief Checks Crc's of all indexes and conditional update of radio configs.
 *
 * \retval #UWBAPI_STATUS_OK        Returns SUCCESS if radio config crc's are correct
 *                                   or update is fine.
 * \retval #UWBAPI_STATUS_FAILED    otherwise
 */
EXTERNC tUWBAPI_STATUS RadioConfig_full(bool force_update);

/**
 * @brief Checks Crc's of all indexes.
 *
 * \retval #UWBAPI_STATUS_OK        Returns SUCCESS if values are "SAME" as
 *                                   expected as per the current release.
 * \retval #UWBAPI_STATUS_FAILED    otherwise
 */
EXTERNC tUWBAPI_STATUS RadioConfig_CheckCrc(void);

/**
 * @brief Radio Config Get CRC api.
 *
 * \param[in] xtalid   param in \ref eGetLutCrc
 * \param[out] pCrc   CRC value
 *
 * \retval #UWBAPI_STATUS_OK                 on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED    if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_INVALID_PARAM      if invalid parameters are passed
 * \retval #UWBAPI_STATUS_TIMEOUT            if command is timeout
 * \retval #UWBAPI_STATUS_FAILED             otherwise
 */
EXTERNC tUWBAPI_STATUS UwbApi_Get_Lut_Crc(eGetLutCrc xtalid, uint16_t *pCrc);

/* Rx_SP1_hprf_Prmbl32_Sfd2_Sts64_1_Data7M8 @ idx=0x08 */
EXTERNC tUWBAPI_STATUS RadioConfig_Rx_SP1_hprf_Prmbl32_Sfd2_Sts64_1_Data7M8_0x08(bool force_update);

/* Rx_SP1_hprf_Prmbl64_Sfd2_Sts64_1_Data7M8 @ idx=0x0A */
EXTERNC tUWBAPI_STATUS RadioConfig_Rx_SP1_hprf_Prmbl64_Sfd2_Sts64_1_Data7M8_0x0A(bool force_update);

/* Tx_SP1_hprf_Prmbl32_Sfd2_Sts64_1_Data7M8 @ idx=0x18 */
EXTERNC tUWBAPI_STATUS RadioConfig_Tx_SP1_hprf_Prmbl32_Sfd2_Sts64_1_Data7M8_0x18(bool force_update);

/* Tx_SP1_hprf_Prmbl64_Sfd2_Sts64_1_Data7M8 @ idx=0x1A */
EXTERNC tUWBAPI_STATUS RadioConfig_Tx_SP1_hprf_Prmbl64_Sfd2_Sts64_1_Data7M8_0x1A(bool force_update);

/**
 * @brief set Bypass current limiter api.
 *
 * \param[in] BypassMode   To Enable/Disable the Bypass  current Limiter
 *
 * \retval #UWBAPI_STATUS_OK                 on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED    if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_INVALID_PARAM      if invalid parameters are passed
 * \retval #UWBAPI_STATUS_TIMEOUT            if command is timeout
 * \retval #UWBAPI_STATUS_FAILED             otherwise
 */

EXTERNC tUWBAPI_STATUS UwbApi_Set_Bypass_Current_Limiter(bool BypassMode);

/**
 * @brief set Radio configuration update from external table.
 *
 * \param[in] radio_settings    Pointer to the phRadioConfigInfo_t
 *
 * \retval #UWBAPI_STATUS_OK                 on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED    if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_INVALID_PARAM      if invalid parameters are passed
 * \retval #UWBAPI_STATUS_TIMEOUT            if command is timeout
 * \retval #UWBAPI_STATUS_FAILED             otherwise
 */
tUWBAPI_STATUS UwbApi_Set_Radio_Configs_Full(phRadioConfigInfo_t *radio_settings);

/**
 * @brief Prepare sharable Configuration Data.
 * \param[in]      pShareableData           : sharable data which contain all information.
 * \param[in]      ShareableDataLength      : Size of sharable data
 * \param[in,out]  pProfileInfo             : contains profile information.
 * \param[in]      noOfAppParams            : number of AppParams.
 * \param[in]      AppParams_List           : List of AppParams to be set.
 *
 * \retval #UWBAPI_STATUS_OK                - on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED   - if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_INVALID_PARAM     - if invalid parameters are passed
 * \retval #UWBAPI_STATUS_FAILED            - otherwise
 */
tUWBAPI_STATUS UwbApi_ConfigureData_iOS(uint8_t *pShareableData,
    uint16_t ShareableDataLength,
    phUwbProfileInfo_t *pProfileInfo,
    uint8_t noOfAppParams,
    const UWB_AppParams_List_t *AppParams_List);

/**
 * @brief Set phone uwb configuration data.
 * \param[in]      pUwbPhoneConfigData      : UwbPhoneConfigData_t data which contain all information.
 * \param[in]      UwbPhoneConfigDataLen    : Size of phone configuration data
 * \param[in,out]  pProfileInfo             : contains profile information
 * \param[in]      noOfAppParams            : number of AppParams.
 * \param[in]      AppParams_List           : List of AppParams to be set.
 *
 * \retval #UWBAPI_STATUS_OK                - on success
 * \retval #UWBAPI_STATUS_NOT_INITIALIZED   - if UWB stack is not initialized
 * \retval #UWBAPI_STATUS_INVALID_PARAM     - if invalid parameters are passed
 * \retval #UWBAPI_STATUS_FAILED            - otherwise
 */
tUWBAPI_STATUS UwbApi_ConfigureData_Android(uint8_t *pUwbPhoneConfigData,
    uint16_t UwbPhoneConfigDataLen,
    phUwbProfileInfo_t *pProfileInfo,
    uint8_t noOfAppParams,
    const UWB_AppParams_List_t *AppParams_List);

#ifdef __cplusplus
} // closing brace for extern "C"
#endif

/** @}  */ /* @addtogroup uwb_apis_sr040 */

#endif // UWBAPI_PROPRIETARY_SR040_H
